<script type="text/javascript" src="/edatfiles/files/scripts/ConfigProperty.js"> </script>
<script type="text/javascript" src="../scripts/common.js"></script>
<script type="text/javascript" src="../scripts/jquery-1.4.2.min.js"/>
<script type="text/javascript" src="../scripts/jquery.ui.core.min.js"></script>
<script type="text/javascript" src="../scripts/jquery.ui.widget.min.js"></script>
<script type="text/javascript" src="../scripts/jquery.ui.tabs.min.js"></script>
<script type="text/javascript" src="../scripts/jquery.jqGrid.min.js"></script>
<script type="text/javascript" src="../scripts/BSV_PopUp.js"></script>

<link type="text/css" href="../css/jquery.ui.all.css" rel="stylesheet" />
<link type="text/css" href="../css/ui.jqgrid.css" rel="stylesheet" />

<link href="../css/eDatCommon.css" rel="stylesheet" type="text/css"/>
<link href="../css/style.css" rel="stylesheet" type="text/css">
<table width="100%" border="0" cellspacing="0" cellpadding="0" id="mainHeaderTable">
    <tr>
        <td width="470"><img src="../image/AS_logo.gif" width="470" height="91"></td>
        <td background="../image/AS_bbkgrnd.gif"><div align="right"><img src="../image/BSV-edat.jpg" width="415" height="25"></div></td>
    </tr>
    <tr>
        <td height="2" valign="top" colspan="2"><img src="../image/blkline.gif" width="100%" height="3"></td>
    </tr>
</table>
<center>
    <div style="text-align:center;" id="mainHeaderDiv">
        <a style="font-weight:bold; font-size:8pt; color:#003399">BOEING PROPRIETARY</a>
        <hr/>
    </div>
</center>
<img src="../image/progress.gif" style="position: absolute; display: none;" width="0" height="0" border="0"/>
<img src="../image/0.png" style="position: absolute; display: none;" width="0" height="0" border="0"/>

<script>
    var flowId = ${flowScope._flowId}
    var currentUrl = window.location.href;
    var isDialog = '${flowScope._dialog}' == 't';
    var dialogAction = '${flowScope._actionMethod}';

    /**
     * Global setup for ajax, auto injected conversation scope (_flowId)
     * to maintain the conversation data when ajax calling
     */
    $.ajaxSetup({
        data: {'_flowId': flowId},

        beforeSend : function(xhr) {
            showOverlay(false, window.parent, true);
            deleteInfoMsg()
            xhr.setRequestHeader('AJAX_REQUEST', 'true');
        },
        success:function(msg) {
            hideOverlay();
        },
        error: function (xhr, status, index, anchor) {
            hideOverlay();
            showMsg("Ajax load error: " + xhr.responseText, 'warn')
        }
    });


    /**
     *  Auto injected conversation scope (_flowId) when forms submited
     *  to maintain the conversation data
     */
    $(document).ready(function() {
        var hiddenFlowId  = document.createElement("input");
        hiddenFlowId.type = "hidden";
        hiddenFlowId.name = "_flowId";
        hiddenFlowId.value = flowId

        var forms = document.forms;
        for (var i = 0; i < forms.length; ++i) {
            var form = forms[i];
            form.onsubmit = function () {
                form.appendChild(hiddenFlowId)
            }
        }
    });


    /**
     * Auto inject action binding parameter (_a) into form submit
     * Page submit action should call this to get auto action binding benefit
     */
    function submitBind(formId, serverAction, beforeSubmit) {
        var hiddenAction = "<input type='hidden' name='_a' value='" + serverAction + "'/>";
        var form = $('#' + formId)
        form.append(hiddenAction);
        form.submit(beforeSubmit);
    }

    /**
     * Auto inject action binding parameter (_a) into ajax call
     * Page ajax operation should call this to get auto action binding benefit
     */
    function ajaxBind(serverAction, params, dataType, successHandler, url, errorHandler, beforeSendHandler) {
        dataType = dataType == null ? 'text' : dataType;
        params = params == null ? {} : params;
        params["_a"] = serverAction
        url = (url == null) ? currentUrl : url;

        $.ajax({
            type: "GET",
            url: url,
            dataType: dataType,
            data: params,
            beforSend: function(xhr) {

                if(beforeSendHandler == null) {
                    showOverlay(false, window.parent, true);
                    deleteInfoMsg()
                    xhr.setRequestHeader('AJAX_REQUEST', 'true');
                } else {
                    beforeSendHandler(xhr)
                }
            },
            error: function(xhr) {
                hideOverlay();

                if(errorHandler != null) {
                    errorHandler(xhr)
                } else {
                    showMsg("Ajax load error: " + xhr.responseText, 'warn')
                }
            },
            success: function (msg) {
                if(successHandler != null) {
                    successHandler(msg);
                }
                hideOverlay();
            }
        });
    }

    /**
     *  Hanling dialog open
     */
    function openDialog(action, dUrl, width, height, title) {

        ajaxBind(action,
        {_dialog : '_open',_a : action},
        'text',
        function(msg) {
            hideOverlay();
            if(msg.indexOf("ERROR") != -1) {

                var errs = msg.split("#");
                var errsTxt = "";
                for(var i = 1; i < errs.length; i++) {
                    errsTxt += errs[i] + "<br/>"
                }

                showMsg(errsTxt, 'warn')

            } else {
                if(!isEmpty(msg)) {
                    var newGenerationDialogFlowIdParam = "_flowId=" + msg;

                    dUrl = dUrl + ((dUrl.indexOf("?") != -1) ? "&" : "?")
                        + newGenerationDialogFlowIdParam

                    popUpNewWin(dUrl, width, height, title);
                }
            }
        }, currentUrl, null, null)
    }

    /**
     *  Hanling dialog close
     *  Internal use only
     */
    function _onDialogClose(dialogUrl, actionMethod) {
        var urlParams = getUrlVars(dialogUrl);
        ajaxBind(actionMethod,
        {
            _dialog : '_closed',
            _flowId: flowId,
            _dialogFlowId: urlParams['_flowId']

        },'text', null, currentUrl, null, null)
    }

    /**
     * It's recommended that page should call this to exit/stop (instead of directly invoke close on js)
     * to release conversation data at server side
     */
    function stopFlow() {
        if(isDialog) {
            window.opener._onDialogClose(currentUrl, dialogAction)
            
        } else {
            $.ajax({
                type: "GET",
                data: {'_flowEnd': 't'}
            });
        }
        
        var top = window.open("", "_top");
        top.close();
    }

</script>